<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            border:1px solid blue;
        }
    </style>
</head>
<body>
    <!-- 画框
    画布 -->
    <canvas width="800" height="600" id="canvas"></canvas>
    <script>
        var canvas = document.getElementById('canvas')
        var huabi = canvas.getContext('2d')
        var img = document.createElement('img')
        img.src = '/1.jpg'
        img.onload = function(){
            huabi.beginPath()
            huabi.rect(50,50,100,50)
            huabi.clip()
            huabi.drawImage(img,0,0)
            //base64的图片的内容
            console.log(canvas.toDataURL('image/png'))
        }
    </script>
</body>
</html>